const express = require('express');
const router = express.Router();

router.get('/', (req, res) => { 
    const content = [];
    for(let i = 0; i < 100; i++)
        content.push({
            id: `2019${i}`,
            dealerCode: `dealerCode${i}`,
            dealerName: `总代名称${i}`,
            code: `XSQRS00${i}`,
            brandCode: 'CHERY',
            salesOrderCode: 'XSCODE20200303001',
            saleProformaInvoiceCode: 'PI20200303001',
            transportType: 1,
            tradeMethodName: '贸易',
            payment: 1,
            salesOrderPriceTerms: 1,
            status: 1,
            totalAmount: 100,
            productAmount: 98,
            shipmentAmount: 1,
            insuranceAmount: 1,
            currency: 1,
            batchNumber: '001',
            approveResult: 1,
            createTime: '2020-03-02T07:49:31.607Z',
            rowVersion: 'rowVersion',
            options: [
                'update',
                'abandon',
                'submit',
                'approve'
            ]
        });
    res.json({
        message: '',
        payload: {
            content,
            totalElements: 100,
        }
    });
});
router.get('/:id', async(req, res, next) => {
    res.json({
        message: '',
        payload: {
            id: '001',
            code: 'Code001',
            dealerId: '1',
            dealerCode: 'dealerCode001',
            dealerName: 'dealerName001',
            brandId: '1',
            brandCode: 'brandCode',
            brandName: 'brandName',
            saleOrderId: '1',
            salesOrderCode: 'XSCODE20200303001',
            saleProformaInvoiceId: '1',
            saleProformaInvoiceCode: 'PI20200303001',
            letterOfCreditId: '1',
            letterOfCreditCode: 'XY20200303001',
            lCVersionCode: '2020.3.001',
            taxRate: 0.16,
            orderType: 1,
            tradeMethodName: '贸易',
            payment: 1,
            salesOrderPriceTerms: 1,
            status: 1,
            totalAmount: 100,
            productAmount: 98,
            shipmentAmount: 1,
            insuranceAmount: 1,
            currency: 1,
            batchNumber: '001',
            marks: 'marks',
            carrierName: 'carrierName',
            shippingPortName: 'shippingPortName',
            destinationPort: 'destinationPort',
            approveComment: 'approveComment',
            approveResult: 1,
            packingWay: 1,
            insurance: 'insurance',
            createTime: '2020-03-02T07:49:31.607Z',
            creatorName: 'creatorName',
            modifierName: 'modifierName',
            modifyTime: '2020-03-02T08:40:53.602Z',
            abandonerName: 'abandonerName',
            abandonTime: '2020-03-02T08:40:53.602Z',
            submitterName: 'submitterName',
            submitTime: '2020-03-02T08:40:53.602Z',
            remark: 'remark',
            rowVersion: 'string',
            nextApproveNumber: 1,
            options: [
                'update',
                'abandon',
                'submit',
                'approve'
            ],
            details: [
                {
                    id: '001',
                    salesOrderDetailId: '1',
                    kdBomCode: 'kdBomCode',
                    kdBomVersionCode: 'kdBomVersionCode',
                    productGroupCode: 'productGroupCode',
                    productCode: 'productCode',
                    productName: 'productName',
                    productCategoryCode: 'productCategoryCode',
                    productCategoryName: 'productCategoryName',
                    quantity: 11,
                    price: 22,
                    taxFreePrice: 22,
                    totalPrice: 22,
                    taxFreeTotalPrice: 22,
                    remark: 'remark',
                }
            ],
            saleConfirmationResults: [
                {
                    id: '001',
                    approverCode: 'approverCode',
                    approverName: 'approverName',
                    approveTime: '2020-03-03T09:30:33.129Z',
                    approveComment: 'approveComment',
                    approveResult: 1,
                    nextOperation: 'nextOperation',
                }
            ]
        }
    });
});

router.post('/', async(req, res, next) => {
    res.json({
        message: '新增成功'
    });
});

router.put('/:id', async(req, res, next) => {
    res.json({
        message: '编辑成功'
    });
});

router.put('/:id/reject', (req, res) => {
    res.json(
        {
            message: '审核成功'
        }
    );
});

router.put('/:id/pass', (req, res) => {
    res.json(
        {
            message: '审核成功'
        }
    );
});

router.put('/:id/submit', (req, res) => {
    res.json(
        {
            message: '提交成功'
        }
    );
});

router.put('/:id/abandon', (req, res) => {
    res.json(
        {
            message: '作废成功'
        }
    );
});

router.get('/export', async(req, res, next) => {
    res.json({
        message: '导出成功',
        payload: 'Mock导出'
    });
});

module.exports = router;
